<?php
/**
 * @Author: Ron Chen
 * @Date:   2017-04-11 00:10:16
 * @Last Modified by:   Ron Chen
 * @Last Modified time: 2017-04-11 00:19:46
 */

namespace app\models;

use Yii;

/**
 * AccountInfo
 */
class AccountInfo extends \yii\db\ActiveRecord
{
	/**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'account';
    }

    public static function initRecord($params){
    	$user_id   =  isset($params["account_id"]) ? $params["account_id"] : 0;
    	$user_info = static::find()->where(['account_id'=>$user_id])->limit(1)->one();
    	if (empty($user_info)) {
    		$user_info = new static();
    		$user_info->status = 'ok';
    		$user_info->create_time = date('Y-m-d H:i:s');
    	}
    	if ($params['nick_name']) {
    		$user_info->nick_name = $params['nick_name'];
    	}
    	if ($params['login_password']) {
    		$user_info->login_password = $params['login_password'];
    	}
    	if ($user_info->save()) {
    		return $user_info->attributes["account_id"];
    	}
    	return 0;
    }
}